/**
 * All rights Reserved, Designed By www.ditingai.com
 *
 * @Title: DynamicProxyHandler
 * @Package com.liufei.proxy
 * @author: 北京谛听机器人科技有限公司
 * @date: 2019/2/18 14:27
 * @version V1.0
 * @Copyright: 2019 www.ditingai.com . All rights reserved.
 * 注意：本内容仅限于北京谛听机器人科技有限公司内部传阅，禁止外泄以及用于其他的商业目
 */
package com.liufei.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Arrays;

/**
 *Description TODO
 *@Author liufei
 *@DATE 2019/2/18 14:27
 **/
public class DynamicProxyHandler implements InvocationHandler {

    private Object proxied;

    public DynamicProxyHandler(Object proxied){
        System.out.println("dynamic proxy handler constuctor: " + proxied.getClass());
        this.proxied = proxied;
    }

    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("dynamic proxy name: " + proxy.getClass());
        System.out.println("method: " + method.getName());
        System.out.println("args: " + Arrays.toString(args));

        Object invokeObject = method.invoke(proxied, args);
        if (invokeObject != null) {
            System.out.println("invoke object: " + invokeObject.getClass());
        } else {
            System.out.println("invoke object is null");
        }
        return invokeObject;
    }
}
